package com.newtouch.bxzs.database.synchronize.batch.step;

import com.newtouch.bxzs.database.synchronize.batch.reader.ReaderData;
import com.newtouch.bxzs.database.synchronize.batch.writer.WriterAchievement;
import com.newtouch.bxzs.database.synchronize.model.achievement.AchievementPolicyVO;
import com.newtouch.bxzs.database.synchronize.model.achievement.AchievementVO;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 业绩同步step
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/1/7 11:00</td>
 * <td>Amour</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author yuanjie
 * @version 1.0.0
 * @since 1.0.0
 */
@Component
public class AchievementStep {

    @Autowired
    private StepBuilderFactory stepBuilderFactory;

    @Autowired
    private ReaderData readerData;

    @Autowired
    private WriterAchievement writerAchievement;


    /**批处理同步个人业绩数据*/
    public Step synchronizeAchievement(){
        return stepBuilderFactory.get("synchronizeAchievement")
                .<AchievementVO, AchievementVO>chunk(100)
                .reader(readerData.getAchievement())
                .writer(writerAchievement.addAchievement())
                .build();
    }

    /**批处理同步个人业绩明细数据*/
    public Step synchronizeAchievementPolicy(){
        return stepBuilderFactory.get("synchronizeAchievementPolicy")
                .<AchievementPolicyVO, AchievementPolicyVO>chunk(100)
                .reader(readerData.getAchievementPolicy())
                .writer(writerAchievement.addAchievementPolicy())
                .build();
    }
}
